package com.dzzw.Servlet.VacationServlet;

import com.dzzw.Dao.VacationDao;
import com.dzzw.Model.Vacation;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/View/VacationAddServlet")
public class VacationAddServlet extends HttpServlet {
    private static final long serialVersionUID = 1L;
    VacationDao vacationDao = new VacationDao();
    public VacationAddServlet(){
        super();
    }
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request, response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("utf-8");
        response.setContentType("text/html;charset=utf-8");
        int employee_id = Integer.parseInt(request.getParameter("employee_id"));
        int leader_id = Integer.parseInt(request.getParameter("leader_id"));
        String vacation_reason = request.getParameter("vacation_reason");
        String vacation_starttime = request.getParameter("vacation_starttime");
        String vacation_endtime = request.getParameter("vacation_endtime");
        Vacation vacation = new Vacation();
        vacation.setEmployee_id(employee_id);
        vacation.setLeader_id(leader_id);
        vacation.setVacation_reason(vacation_reason);
        vacation.setVacation_starttime(vacation_starttime);
        vacation.setVacation_endtime(vacation_endtime);
        vacationDao.VacationAdd(vacation);
        response.sendRedirect("/View/SelectVacationByEmployeeId.jsp");
    }
}
